package gemini.castor.ui.client.page.content.office.events.widget;

import gemini.basic.model.Event;

import com.google.gwt.event.shared.GwtEvent;

/**
 * The event collections of internal widget for screen uk 1-21.010-a
 */
public class EventsTableEvent extends GwtEvent<EventsTableHandler> {

	private static Type<EventsTableHandler> TYPE;

	public static Type<EventsTableHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<EventsTableHandler>();
		return TYPE;
	}
	
	private Event event;
	
	public enum EventType {
		EDIT, DELETE, ADD
	}
	
	private EventType eventType;
	
	public EventsTableEvent(){
		this.eventType = EventType.ADD;
	}
	
	public EventsTableEvent(EventType eventType, Event event){
		this.event = event;
		this.eventType = eventType;
	}

	@Override
	protected void dispatch(EventsTableHandler handler) {
		if(eventType.equals(EventType.ADD)){
		handler.onAdd(this);
		} else if(eventType.equals(EventType.DELETE)){
		handler.onDelete(this);
		} else if(eventType.equals(EventType.EDIT)){
		handler.onEdit(this);
		}
	}

	@Override
	public Type<EventsTableHandler> getAssociatedType() {
		return getType();
	}
	
	public Event getEvent() {
		return event;
	}
}
